<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Db;

/**
 * Class UserController
 * @package app\admin\controller
 * @adminMenuRoot(
 *     'name'   => '管理组',
 *     'action' => 'default',
 *     'parent' => 'user/AdminIndex/default',
 *     'display'=> true,
 *     'order'  => 10000,
 *     'icon'   => '',
 *     'remark' => '账户明细'
 * )
 */
class BalanceController extends AdminBaseController
{

	 public function index()
    {

    	$where=[];
        /**搜索条件**/
        $userLogin = $this->request->param('user_login');
        $userEmail = trim($this->request->param('user_email'));

        if ($userLogin) {
            $where['u.user_login'] = ['like', "%$userLogin%"];
        }

        if ($userEmail) {
            $where['u.user_email'] = ['like', "%$userEmail%"];;
        }
        $type = input('param.type/s');
        if($type){
        	$where['b.balance_type'] =$type;
        }
        $rows = model('balance')
                ->alias('b')
                ->join('user u','b.user_id=u.id','left')
	            ->where($where)
	            ->order("b.create_at DESC")
	            ->field('b.*, u.user_login,u.user_email')
	            ->paginate(10);
        // 获取分页显示
        $page = $rows->render();
        $this->assign("page", $page);
        $this->assign("rows", $rows);
        return $this->fetch();
    }


    function delete(){
    	$id = input('param.id/d');
    	model('balance')->where('id',$id)->delete();
    	return $this->success('删除成功',url('balance/index'));
    }
}